package com.infocoll.pachou;

import com.infocoll.pachou.biz.UserService;
import com.infocoll.pachou.util.PcConstants;
import com.infocoll.pachou.util.SpringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
import java.io.File;

@SpringBootApplication
public class PachouApplication {

    @Autowired
    UserService UserService;
    
    public static void main(String[] args) {
        // test();
        SpringApplication.run(PachouApplication.class, args);
//        System.out.println("args = " + args[0]);
//        // UserService.save();

        ApplicationContext context = SpringUtil.getApplicationContext();
        UserService userService = context.getBean(UserService.class);
        System.out.println("userOp = " + userService);

        PcConstants pcConstants = context.getBean(PcConstants.class);
        System.out.println("pcConstants.address = " + pcConstants.address);
        try {
            String dir=null;
            if(args==null && args.length==0){
//                请输入地址
                 return;
            }

            dir=args[0];

            File file = new File(dir);

            File[] files = file.listFiles();
            for (File item: files) {

                System.out.println("path::" + item.getName()+" == "+item.getAbsolutePath()+"/html");

                try {
                    userService.parse(item.getAbsolutePath()+"/html", item.getName() );
                } catch (Exception e) {
                    e.printStackTrace();
                }

            }

            // userService.parse(dir);

        } catch (Exception e) {
            e.printStackTrace();
        }
        System.out.println("Running end. \n Total size:: "+ userService.findAll());
    }

    private static void test() {
//        int imagestart = ("https://"+pcConstants.address).length();
//        String src="https://pcConstants.address/supp/list_1.png";
//        if(src.indexOf("https://pcConstants.address")!=-1){
//            src = src.substring(imagestart);
//        }
//        System.out.println("src. = " + src);

    }


}
